package com.wish233.wiliwilivideo.controller;

import com.wish233.wiliwilicommon.common.BaseResponse;
import com.wish233.wiliwilicommon.common.ErrorCode;
import com.wish233.wiliwilicommon.common.ResultUtils;
import com.wish233.wiliwilicommon.exception.BusinessException;
import com.wish233.wiliwilicommon.exception.ThrowUtils;
import com.wish233.wiliwilivideo.domain.dto.likes.LikeCreateRequest;
import com.wish233.wiliwilivideo.domain.dto.likes.LikeQueryRequest;
import com.wish233.wiliwilivideo.service.LikesService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author WHH
 */
@RestController
@RequestMapping("/like")
public class LikeController {

    @Resource
    private LikesService likesService;

    @ApiOperation("新增点赞记录")
    @PostMapping("/record")
    public BaseResponse<Long> recordLike(@RequestBody LikeCreateRequest likeCreateRequest) {
        ThrowUtils.throwIf(likeCreateRequest == null, new BusinessException(ErrorCode.PARAMS_ERROR));
        Long l = likesService.recordLike(likeCreateRequest);
        return ResultUtils.success(l);
    }

    @ApiOperation("查询点赞数")
    @GetMapping("/query")
    public BaseResponse<Long> queryLikeNum(@RequestParam Integer bizId, @RequestParam Long messageId) {
        ThrowUtils.throwIf(bizId == null || messageId == null, new BusinessException(ErrorCode.PARAMS_ERROR));
        LikeQueryRequest likeQueryRequest = new LikeQueryRequest(bizId, messageId);
        return ResultUtils.success(likesService.queryLikeNum(likeQueryRequest));
    }

}
